var app = new Vue({
	el: '#app',
	data: {
		topPageNewss: {}, //第一条时文
		pageNewss: [], //时文推荐
		shares: [], //右上股票指数
		topNews: {}, //第一条新闻
		news: [], //左边股票新闻
		newsMore:false,//更多新闻
		tabActive: 0, //激活Tab
		url:{
			getPageNewss: '/api/News/GetPageNewss', //时文推荐
			getPageIndexForApp: '/api/Index/GetPageIndexForApp', //实时股票
			getPageTodayNewss: '/api/News/GetPageTodayNewss', //今日新闻
		},
		infos:{
			user:globalData.userInfo
		},//用户的所有信息
	},
	mounted: function() {
		var that = this;		
		globalData.getTempToken(function(){
			that.getPageNewss();
			that.getPageIndexForApp("股指类涨跌幅", 0);
			that.getPageTodayNewss();
		})
		
	},
	methods: {
		//获取时文
		getPageNewss: function() {
			var that = this;
			var data = {
				PageIndex: 1,
				PageSize: 100,
				CateogyId: 2
			}
			globalData.ajaxPost(this.url.getPageNewss, data, function(res) {
				console.log('asfdddddddddd')
				var d = res.data;
				if(d == null)
					d = [];
				if(d.length > 0) {
					var dd = d[0];
					if(dd.Image == null)
						dd.Image = "";
					else
						dd.Image = globalData.constParam.url.baseUrl + "/" + dd.Image;
					that.topPageNewss = d[0];
				}
				var newss = [];
				for(var i = 0; i < d.length; i++) {
					newss.push(d[i]);
				}
				that.pageNewss = newss;
				console.log(that.pageNewss)
				//隐藏loading
				$('.loading').hide()
			})
		},
		//获取股票类别信息
		getPageIndexForApp: function(name, tabActive) {
			var that = this;
			this.tabActive = tabActive;
			var data = {
				CategoryName: name,
				PageIndex: 1,
				PageSize: 10
			};
			globalData.ajaxPost(this.url.getPageIndexForApp, data, function(res) {
				var d = res.data;
				d = d == null ? [] : d;
				that.shares = d;
			})
		},
		//获取今日新闻
		getPageTodayNewss: function() {
			var that = this;
			data = {
				PageIndex: 1,
				PageSize: 100,
				CateogyId: 1
			}
			globalData.ajaxPost(this.url.getPageTodayNewss, data, function(res) {
				var d = res.data;
				if(d == null)
					d = [];
				if(d.length > 0)
					that.topNews = d[0];
				var news = [];
				for(var i = 0; i < d.length; i++) {
					var objd = d[i];
					if(objd.Image != null)
						objd.Image = globalData.constParam.url.baseUrl + "/" + objd.Image;
					news.push(objd);
				}
				that.news = news;
				console.log(that.news)
			})
		},
		//新闻事件
		newsHref: function(newid) {
			this.shhref(newid);
		},
		//时文事件
		shhref: function(newid) {
			var obj = {
				id:newid
			}
			var url = "news_detail.html"
			globalData.utils.setUrl(url,obj)
		}
	}
})